home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Philippe Verdy <100105.3120@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Recognizing class instantiation type?
- Date: 31 Mar 1996 19:27:47 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4jmmbj$ojt@arl-news-svc-5.compuserve.com>
- NNTP-Posting-Host: hd80-162.compuserve.com
-
- danubius@coho.halcyon.com () s'Θcrit :
- > Is there any way to determine inside of a class whether it was
- > instantiated in the dynamic memory (with "new"), or on the stack?
- >
- > Thanks,
- > Joe
- Apparently no.
- But I see what you mean: do you have to delete the object
- or not ?
- This object deletion should only be done in the class or
- function that allocated it using the new operator.
- It's up to you to build your classes so that you can track
- dynamically allocated objects. Such object pointers should be
- always stored in a variable prior to using them, so that
- future destruction is possible using the same pointer.
-
- It may be deleted later, but then you'll have to register
- this pointer in another class instance or in a container
- so that deleting this other instance or container will
- delete these objects in a appropriate way.
-
- For all other, let the compiler do the stuff for calling destructors
- on local and static instances...
-
- So you must not rely on where objects are allocated to know
- if the object has to be deleted or not.
- If this is critical, you'll have to create a placement new
- operator which registers the new object within a container
- specified by the placement.
-
-